import {userController} from "./UserController";
import axios from "axios";
import {urlConfig} from "../Config";

const fetchPassengers = async () => {
    if (userController.isLogged()) {
        const account = userController.getUserInfo()?.account;
        const msg = await axios.get(urlConfig.getUrlFor("/passenger", {account}));
        return msg.data;
    }
    return [];
};

const addPassenger = async (passenger: any)=>{
    if (userController.isLogged()) {
        passenger.account = userController.getUserInfo()?.account;
        await axios.post(urlConfig.getUrlFor("/passenger", passenger));
    }
}

const rmPassenger = async (id: any) => {
    if (userController.isLogged()) {
        await axios.delete(urlConfig.getUrlFor("/passenger/"+id));
    }
}

export {fetchPassengers, addPassenger, rmPassenger};